package PredefinedData;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

import Analysis.CorrelationManagerClass;
import ClassificationAlgorithm.CoTrainAlgorithmClass;
import ClassificationAlgorithm.ContentOnlyClass;
import ClassificationAlgorithm.ICAClass;
import ClassificationAlgorithm.LinkOnlyClass;
import ContentToLink.ContentToLinkConverterClass;
import ContentToLink.ContentToLinkConverterDataClass;
import Definitions.EdgeClass;
import Definitions.GraphClass;
import Definitions.NodeClass;
import FeatureEnrichment.FeatureEnrichment;
import Global.ConstantVariable;
import Global.ConstantVariable.FEATURE_ENRICHMENT_PROPERTIES;
import Global.DirectoryStructureAndSettingsClass;
import Global.GlobalClass;
import Integrity.IntegrityCheckerClass;
import LatexForResults.LatexUtilityForPredefinedDatasetsResultsClass;
import LatexForResults.LatexUtilityForPredefinedDatasetsResultsClass.predefinedDatasetExtendedResultsTableCreatorClass;
import MetaClassifierAlgorithms.MetaClassifierManagerClass;
import Read.ReadTest;
import Result.ResultClass;
import Result.ResultClassListClass;
import Sampling.SamplingAbstractClass;
import Sampling.SamplingFactory;
import Statistics.statisticsManagerClass;
import Test.TestParameterManager;
import Utility.FileUtilityClass;

public class PredefinedDataManager {
	
	static BufferedWriter outForPredefinedDatasetsSummaryResultsFile;				
	static BufferedWriter outForPredefinedDatasetsFoldsResultsFile;
	static BufferedWriter outForPredefinedDatasetsExtendedResultsFile;	
	
	static ResultClassListClass  resultsForCO = null;
	static ResultClassListClass  resultsForLO = null;
	static ResultClassListClass  resultsForICA = null;
	
	static ResultClassListClass  resultsForAVE = null;
	static ResultClassListClass  resultsForMAX = null;
	static ResultClassListClass  resultsForPROD = null;
	
	static ResultClassListClass  resultsForLA = null;
	static ResultClassListClass  resultsForDFMM = null;
	
	static ResultClassListClass  resultsForLB = null;
	
	
	static ResultClassListClass  resultsForLAMAX = null;
	static ResultClassListClass  resultsForLBMAX = null;

	static ResultClassListClass resultsForEnrichedAllCOTRAIN = null;
	static ResultClassListClass resultsForPlainCoTrain = null;
	static ResultClassListClass resultsForOrCoTrain = null;
	static ResultClassListClass resultsForNeighoursCoTrain = null;
	
	
	
	public static void ManageMultipleTests(GraphClass graph, GlobalClass global, String datasetName) 
	{
		ReadTest.Test(GlobalClass.RunningValues.executionFor, graph, global);
/*
		FeatureEnrichment enrichment = new FeatureEnrichment();
		enrichment.setOriginalAttributes(graph);
	    FEATURE_ENRICHMENT_PROPERTIES.selected = ConstantVariable.FEATURE_ENRICHMENT_PROPERTIES.OR;
		enrichment.setAttributes(graph);
*/
		//ContentToLinkConverterClass ContentToLinkConverter = new ContentToLinkConverterClass(graph, ConstantVariable.Common_ConstantVariables.DEFAULT_CONTENT_TYPE, ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH, datasetName);
		/*
		if(FileUtilityClass.checkIfFileExists(IntegrityCheckerClass.getFileNameForSimilarityForContentObject())==false)
		{			
			ContentToLinkConverter.createSimilarityMatrixInParallel();
			FileUtilityClass.writeObjectToFile(ContentToLinkConverter.getContentToLinkConverterData(), IntegrityCheckerClass.getFileNameForSimilarityForContentObject());
		}
		else
		{
			System.out.println("Sim. yukleniyor...");
			ContentToLinkConverter.setContentToLinkConverterData((ContentToLinkConverterDataClass)FileUtilityClass.readObjectFromFile(IntegrityCheckerClass.getFileNameForSimilarityForContentObject()));
			System.out.println("Sim. yuklendi...");
			ContentToLinkConverter.createAdjacencyMatrixOfTheContentGraphWithTheThresholdLevel();
			System.out.println("Sim. createAdjacencyMatrixOfTheContentGraphWithTheThresholdLevel OK...");
		}*/

		 SamplingFactory samplingFactory = new SamplingFactory();
		 SamplingAbstractClass sampling;
		
		 String outputFile = "GeneralResultsICA.txt";		 
		 String samplingName = ConstantVariable.Sampling_Constants.RANDOM_SAMPLING_METHOD;//(String)args[3];
		 Object[] samplingArgs = TestParameterManager.getSamplingParametres(samplingName);

		 try{
			  // Create file 
			  FileWriter fstream = new FileWriter(outputFile);
			  BufferedWriter out = new BufferedWriter(fstream);
			  out.write("% General Results CO");
			  out.newLine();
			  out.write("% Random Sampling ");
			  out.newLine();
			  
	//		 for(int i=0; i<1; i++)
	//		 {
				sampling = samplingFactory.createSampling(graph, global, samplingName, samplingArgs);		

				float testRatio = ((Double)samplingArgs[0]).floatValue();
				float trainRatio = ((Double)samplingArgs[3]).floatValue();
				
				/*
				if(trainRatio>testRatio)
					break;
				*/
				out.write("% TestRatio: " + testRatio + "  TrainRatio: " + trainRatio);
				out.newLine();

					
				if(ConstantVariable.ExecutionParameters.isContentOnlyExecutionEnabled)
				{
					// Sampling koyabilsen içine 					
					out.write("% Co");
					out.newLine();

					resultsForCO = ContentOnlyClass.TestWithWekaInParallelStart(graph, global, ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_CONTENT_ONLY, sampling, ConstantVariable.ExecutionParameters.SELECTED_LOCAL_CLASSIFIER, ConstantVariable.ExecutionParameters.SELECTED_SECOND_LEVEL_LOCAL_CLASSIFIER);
					
					for(int k=0 ; k<5; k++)
					{
						ResultClass result = resultsForCO.get(k);
						out.write(result.getIdentifier().getFold()+ "   " + result.getAccuracy());
						out.newLine();
					}

				}
				
				if(ConstantVariable.ExecutionParameters.isLinkOnlyExecutionEnabled)
				{
					resultsForLO = LinkOnlyClass.TestWithWekaInParallelStart(graph, global, ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_LINK_ONLY, sampling, ConstantVariable.ExecutionParameters.SELECTED_LOCAL_CLASSIFIER, ConstantVariable.ExecutionParameters.SELECTED_SECOND_LEVEL_LOCAL_CLASSIFIER);
					
					out.write("% Lo");
					out.newLine();
					
					for(int k=0 ; k<5; k++)
					{
						ResultClass result = resultsForLO.get(k);
						out.write(result.getIdentifier().getFold()+ "   " + result.getAccuracy());
						out.write("   " + result.getStartAccuracy() + "  " + result.getEndAccuracy());
						out.newLine();
					}
				}
		
				if(ConstantVariable.ExecutionParameters.isICAExecutionEnabled)//
				{
					 resultsForICA = ICAClass.TestWithWekaInParallelStart(graph, global, ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_ICA, sampling, ConstantVariable.ExecutionParameters.SELECTED_LOCAL_CLASSIFIER, ConstantVariable.ExecutionParameters.SELECTED_SECOND_LEVEL_LOCAL_CLASSIFIER);

						out.write("% ICA");
						out.newLine();
					for(int k=0 ; k<5; k++)
					{
						ResultClass result = resultsForICA.get(k);
						out.write(result.getIdentifier().getFold()+ "   " + result.getAccuracy());
						out.write("   " + result.getStartAccuracy() + "  " + result.getEndAccuracy());
						out.newLine();
					}
				}
				
				
		//		samplingArgs[0] = testRatio - 0.1;
		//		samplingArgs[3] = trainRatio + 0.1;  
//			 }
	
			 samplingArgs = TestParameterManager.getSamplingParametres(samplingName);
			 samplingName = ConstantVariable.Sampling_Constants.SNOWBALL_SAMPLING_METHOD;
			  out.write("% Snowbal Sampling ");
			  out.newLine();
			// for(int i=0; i<5; i++)
			// {
				 
				 sampling = samplingFactory.createSampling(graph, global, samplingName, samplingArgs);		
			//	float testRatio = ((Double)samplingArgs[0]).floatValue();
			//	float trainRatio = ((Double)samplingArgs[3]).floatValue();
				out.write("% TestRatio: " + testRatio + "  TrainRatio: " + trainRatio);
				out.newLine();

				/*
				if(trainRatio>testRatio)
					break;
				*/					 
				if(ConstantVariable.ExecutionParameters.isContentOnlyExecutionEnabled)
				{
					// Sampling koyabilsen içine 
					resultsForCO = ContentOnlyClass.TestWithWekaInParallelStart(graph, global, ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_CONTENT_ONLY, sampling, ConstantVariable.ExecutionParameters.SELECTED_LOCAL_CLASSIFIER, ConstantVariable.ExecutionParameters.SELECTED_SECOND_LEVEL_LOCAL_CLASSIFIER);

					out.write("% CO");
					out.newLine();
					for(int k=0 ; k<5; k++)
					{
						ResultClass result = resultsForCO.get(k);
						out.write(result.getIdentifier().getFold()+ "   " + result.getAccuracy());
						out.newLine();
					}
				}
				
				if(ConstantVariable.ExecutionParameters.isLinkOnlyExecutionEnabled)
				{
					out.write("% LO");
					out.newLine();
					resultsForLO = LinkOnlyClass.TestWithWekaInParallelStart(graph, global, ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_LINK_ONLY, sampling, ConstantVariable.ExecutionParameters.SELECTED_LOCAL_CLASSIFIER, ConstantVariable.ExecutionParameters.SELECTED_SECOND_LEVEL_LOCAL_CLASSIFIER);
					
					for(int k=0 ; k<5; k++)
					{
						ResultClass result = resultsForLO.get(k);
						out.write(result.getIdentifier().getFold()+ "   " + result.getAccuracy());
						out.write("   " + result.getStartAccuracy() + "  " + result.getEndAccuracy());
						out.newLine();
					}
				}
		
				if(ConstantVariable.ExecutionParameters.isICAExecutionEnabled)//
				{
					 resultsForICA = ICAClass.TestWithWekaInParallelStart(graph, global, ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_ICA, sampling, ConstantVariable.ExecutionParameters.SELECTED_LOCAL_CLASSIFIER, ConstantVariable.ExecutionParameters.SELECTED_SECOND_LEVEL_LOCAL_CLASSIFIER);
						out.write("% ICA");
						out.newLine();
					for(int k=0 ; k<5; k++)
					{
						ResultClass result = resultsForICA.get(k);
						out.write(result.getIdentifier().getFold()+ "   " + result.getAccuracy());
						out.write("   " + result.getStartAccuracy() + "  " + result.getEndAccuracy());
						out.newLine();
					}
				}		
				
				
			//	samplingArgs[0] = testRatio - 0.1;
			//	samplingArgs[3] = trainRatio + 0.1;  
			 //}

		  out.close();
		  }catch (Exception e){//Catch exception if any
		  System.err.println("Error: " + e.getMessage());
		  }
	}
	
	
	/***
	 * 
	 * @param graph
	 * @param global
	 * @param datasetName
	 * @param args
	 * 
	 * args[0] parameters for M
	 * args[1] parameters for enriched feature 
	 * args[2] parameters for K classifier sizes 
	 */
/*	
	public static void ManageCoTrainExecution(GraphClass graph, GlobalClass global, String datasetName, Object...args) {
		 
		ReadTest.Test(GlobalClass.RunningValues.executionFor, graph, global);
		String outputFileName = "/ROOT/CO_TRAIN_RESULTS/"+datasetName; 

		int featureSize = graph.getDataSet().get(0).getContentList().get(0).getAttributeList().size();
		
		FeatureEnrichment enrichment = new FeatureEnrichment();
		enrichment.setOriginalAttributes(graph);
		 
		int[] testParametresOfM = null;
		String[] testParametersOfFeatureEnrichement = null;
		int[] testParametersOfK = null;
		String samplingName = "";
		
		if(args != null ) {
			 // FeatureSize
		    testParametresOfM = (int[])args[0];
		    testParametersOfFeatureEnrichement = (String[]) args[1];
		    testParametersOfK = (int[])args[2];
		    
		    samplingName = (String)args[3];
		    
		    
		    if(args.length>2) {
		    	// Sampling size set dynamically...
		    	System.out.print("Bu bakalim");
		    }
		 }		
		 

		 SamplingFactory samplingFactory = new SamplingFactory();
		 SamplingAbstractClass sampling;
		
		 String outputFile;
		 
		 try {
			 

			 Object[] coTrainParams = new Object[5];
			 
			 for(int K : testParametersOfK) {
				 
				 for(String featureEnrichmentMethod : testParametersOfFeatureEnrichement) {
					 
					 FEATURE_ENRICHMENT_PROPERTIES.selected = featureEnrichmentMethod;
					//
					 System.out.print("Bu ksıım eksik...");
					 //enrichment.setAttributes(graph);
					 Object[] samplingArgs = TestParameterManager.getSamplingParametres(samplingName);
					 sampling = samplingFactory.createSampling(graph, global, samplingName, samplingArgs);		

					 for(int M : testParametresOfM) {
						 
						 System.out.print("K : " + K + " method: " + featureEnrichmentMethod + " M: " + M );
						 M = M * (featureSize/100);
						 double testRatio = (Double)samplingArgs[0];
						 outputFile = "_Sampling_" + samplingName+"_TestRatio_" + testRatio+"_K_" + K + "_M_" + M + "_FeatureEnrichment_" + featureEnrichmentMethod +"_numberOfIteration_" + ConstantVariable.EXECUTION_FOR_COTRAIN.iterationNumberForCoTraining;
						 // output file name de ver
						 coTrainParams[0] = outputFile;
						 coTrainParams[1] = M;
						 coTrainParams[2] = K;
						 coTrainParams[3] = ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_COTRAIN;
						 coTrainParams[4] = 5;
						 
						 resultsForPlainCoTrain = CoTrainAlgorithmClass.TestWithWekaInParallelStart(graph, global, sampling, coTrainParams);
					 }	
				 }
			 }
			 
		 } catch (NullPointerException exception) {
			 System.err.println("" + exception.getMessage());
			 exception.printStackTrace();
		 } 
	
		// TODO(KADRIYEB) Investigate this situation.
		if(ConstantVariable.ExecutionParameters.isICAExecutionEnabled)//
		{
			 resultsForICA=ICAClass.TestWithWekaInParallelStart(graph, global, ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_ICA, null, ConstantVariable.ExecutionParameters.SELECTED_LOCAL_CLASSIFIER, ConstantVariable.ExecutionParameters.SELECTED_SECOND_LEVEL_LOCAL_CLASSIFIER);
		}
	}
	
*/	
	
	@SuppressWarnings("unused")
	public static void ManageTestOfPredefinedDatasets(GraphClass graph, GlobalClass global, String datasetName) throws IOException
	{		

		DirectoryStructureAndSettingsClass.setDatasetName(datasetName);
		ReadTest.Test(GlobalClass.RunningValues.executionFor, graph, global);
		
		
		ContentToLinkConverterClass ContentToLinkConverter = new ContentToLinkConverterClass(graph, ConstantVariable.Common_ConstantVariables.DEFAULT_CONTENT_TYPE, ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH, datasetName);
		
		if(FileUtilityClass.checkIfFileExists(IntegrityCheckerClass.getFileNameForSimilarityForContentObject())==false)
		{			
			ContentToLinkConverter.createSimilarityMatrixInParallel();
			FileUtilityClass.writeObjectToFile(ContentToLinkConverter.getContentToLinkConverterData(), IntegrityCheckerClass.getFileNameForSimilarityForContentObject());
		}
		else
		{
			System.out.println("Sim. yukleniyor...");
			ContentToLinkConverter.setContentToLinkConverterData((ContentToLinkConverterDataClass)FileUtilityClass.readObjectFromFile(IntegrityCheckerClass.getFileNameForSimilarityForContentObject()));
			System.out.println("Sim. yuklendi...");
			ContentToLinkConverter.createAdjacencyMatrixOfTheContentGraphWithTheThresholdLevel();
			System.out.println("Sim. createAdjacencyMatrixOfTheContentGraphWithTheThresholdLevel OK...");
			
		}
		
	
		if(ConstantVariable.ExecutionParameters.calculateGraphPropertiesForLinkGraph==true)
		{
			statisticsManagerClass statisticsManagerForLink = new statisticsManagerClass(graph, global, ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE, datasetName);		
			statisticsManagerForLink.execute();
	//		FileUtilityClass.writeObjectToFile(statisticsManagerForLink, IntegrityCheckerClass.getFileNameForPrevLinkGraphPropsObject());
		}

		if(ConstantVariable.ExecutionParameters.calculateGraphPropertiesForContentGraph==true)
		{
			statisticsManagerClass statisticsManagerForContent = new statisticsManagerClass(graph, global, ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH, datasetName);		
			statisticsManagerForContent.execute();
		}
			
		statisticsManagerClass.tryToPrepareGraphPropsSummary(graph, global);
		
		
		ArrayList<NodeClass> datasetOfTheGraph = graph.getDataSet();
		int sizeOfTheGraph = datasetOfTheGraph.size();
		
		for(int i=0; i<sizeOfTheGraph; i++)
		{
			EdgeClass orgEdgeList = datasetOfTheGraph.get(i).getEdgeList().get(0);
			EdgeClass contentEdgeList = datasetOfTheGraph.get(i).getEdgeList().get(1);
			
			datasetOfTheGraph.get(i).getEdgeList().clear();
			
			datasetOfTheGraph.get(i).getEdgeList().add(contentEdgeList);
			datasetOfTheGraph.get(i).getEdgeList().add(orgEdgeList);
		}
		
		ArrayList<ResultClassListClass> resultsOfAlgorihms = new ArrayList<ResultClassListClass>();

		if(ConstantVariable.ExecutionParameters.isContentOnlyExecutionEnabled)
		{
			resultsForCO = ContentOnlyClass.TestWithWekaInParallelStart(graph, global, ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_CONTENT_ONLY, null, ConstantVariable.ExecutionParameters.SELECTED_LOCAL_CLASSIFIER, ConstantVariable.ExecutionParameters.SELECTED_SECOND_LEVEL_LOCAL_CLASSIFIER);				
		}
		
		if(ConstantVariable.ExecutionParameters.isLinkOnlyExecutionEnabled)
		{
			resultsForLO = LinkOnlyClass.TestWithWekaInParallelStart(graph, global, ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_LINK_ONLY, null, ConstantVariable.ExecutionParameters.SELECTED_LOCAL_CLASSIFIER, ConstantVariable.ExecutionParameters.SELECTED_SECOND_LEVEL_LOCAL_CLASSIFIER);
		}

		if(ConstantVariable.ExecutionParameters.isICAExecutionEnabled)//
		{
			 resultsForICA = ICAClass.TestWithWekaInParallelStart(graph, global, ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_ICA, null, ConstantVariable.ExecutionParameters.SELECTED_LOCAL_CLASSIFIER, ConstantVariable.ExecutionParameters.SELECTED_SECOND_LEVEL_LOCAL_CLASSIFIER);
		}
		
	
		if(ConstantVariable.ExecutionParameters.isMetaClassifierExecutionEnabled)
		{
			ArrayList<ResultClassListClass> resultsOfMetaAlgorihms = new ArrayList<ResultClassListClass>();
			if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierAverageMethodEnabled)
				resultsForAVE = new ResultClassListClass();
			
			if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierMaxMethodEnabled)
				resultsForMAX = new ResultClassListClass();
			
			if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierProductMethodEnabled)
				resultsForPROD = new ResultClassListClass();
			
			if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalAlphaMethodEnabled)
				resultsForLA = new ResultClassListClass();
			
			if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierDegreeFilterMethodEnabled)
				resultsForDFMM = new ResultClassListClass();
			
			if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalBetaMethodEnabled)
				resultsForLB = new ResultClassListClass();
			
			if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalAlphaMaxMethodEnabled)
				resultsForLAMAX = new ResultClassListClass();
			
			if(ConstantVariable.MetaClassifierExecutionParameters.isMetaClassifierLocalBetaMaxMethodEnabled)
				resultsForLBMAX = new ResultClassListClass();
			
			resultsOfMetaAlgorihms.add(resultsForAVE);
			resultsOfMetaAlgorihms.add(resultsForMAX);
			resultsOfMetaAlgorihms.add(resultsForPROD);
			resultsOfMetaAlgorihms.add(resultsForLA);
			resultsOfMetaAlgorihms.add(resultsForDFMM);
			resultsOfMetaAlgorihms.add(resultsForLB);
			resultsOfMetaAlgorihms.add(resultsForLAMAX);
			resultsOfMetaAlgorihms.add(resultsForLBMAX);			
			
			MetaClassifierManagerClass.TestInParallelStart(graph, global, ConstantVariable.CCA_ConstantVariables.NUMBER_OF_FOLDS_FOR_META_CLASSIFIER, null, resultsOfMetaAlgorihms);
		}
		
		resultsOfAlgorihms.add(resultsForCO);
		resultsOfAlgorihms.add(resultsForLO);
		resultsOfAlgorihms.add(resultsForICA);
	
		resultsOfAlgorihms.add(resultsForAVE);
		resultsOfAlgorihms.add(resultsForMAX);
		resultsOfAlgorihms.add(resultsForPROD);
		resultsOfAlgorihms.add(resultsForLA);
		resultsOfAlgorihms.add(resultsForDFMM);
		resultsOfAlgorihms.add(resultsForLB);
	
		resultsOfAlgorihms.add(resultsForLAMAX);
		resultsOfAlgorihms.add(resultsForLBMAX);	
		
		if(ConstantVariable.ExecutionParameters.calculateGraphPropertiesForLinkGraph==true && ConstantVariable.ExecutionParameters.calculateGraphPropertiesForContentGraph==true)
			evaluationOfOnePredefinedDatasetIsCompletedEvent(resultsOfAlgorihms, graph, datasetName);
		predefinedDataTestEndEvent(datasetName);
		
	}
	
    public static BufferedWriter createPredefinedDatasetSummaryResultsFile(String datasetName)
    {
    	String path= ConstantVariable.DefaultDirectoryNamesConstants.ROOT_DIRECTORY
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderRootDirectory.LATEST_RESULTS_DIRECTORY
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderLatestResultsDirectory.PREDIFINED_DATASETS_RESULTS_DIRECTORY;
    	try {
    		
    		File descFile=DirectoryStructureAndSettingsClass.createFile(path, datasetName+"SummaryResults.tex");
    		FileWriter fstream;
    		fstream = new FileWriter(descFile);
    		BufferedWriter out = new BufferedWriter(fstream);
    		return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    public static BufferedWriter createPredefinedDatasetFoldsResultsFile(String datasetName)
    {
    	String path= ConstantVariable.DefaultDirectoryNamesConstants.ROOT_DIRECTORY
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderRootDirectory.LATEST_RESULTS_DIRECTORY
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderLatestResultsDirectory.PREDIFINED_DATASETS_RESULTS_DIRECTORY;
    	try {
    		
    		File descFile=DirectoryStructureAndSettingsClass.createFile(path, datasetName+"FoldsResults.tex");
    		FileWriter fstream;
    		fstream = new FileWriter(descFile);
    		BufferedWriter out = new BufferedWriter(fstream);
    		return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    public static BufferedWriter createPredefinedDataExtendedResultsFile()
    {
    	String path= ConstantVariable.DefaultDirectoryNamesConstants.ROOT_DIRECTORY
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderRootDirectory.LATEST_RESULTS_DIRECTORY
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderLatestResultsDirectory.PREDIFINED_DATASETS_RESULTS_DIRECTORY;
    	
    	try {
    		
    		File descFile=DirectoryStructureAndSettingsClass.createFile(path, DirectoryStructureAndSettingsClass.getDatasetName()+ConstantVariable.DefaultFileNamesConstants.EXTENDED_RESULTS_FILE_SUFFIX);
    		FileWriter fstream;
    		fstream = new FileWriter(descFile);
    		BufferedWriter out = new BufferedWriter(fstream);
    		return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    static void predefinedDataTestStartEvent(String datasetName)
    {
		outForPredefinedDatasetsSummaryResultsFile = createPredefinedDatasetSummaryResultsFile(datasetName);
		outForPredefinedDatasetsFoldsResultsFile = createPredefinedDatasetFoldsResultsFile(datasetName);
		outForPredefinedDatasetsExtendedResultsFile = createPredefinedDataExtendedResultsFile();	

		
		LatexUtilityForPredefinedDatasetsResultsClass.predefinedDatasetSummaryResultsTableCreatorClass.printLatexpredefinedDatasetSummaryResultsTableHeaderFirstPartToTheFile(outForPredefinedDatasetsSummaryResultsFile, datasetName);
    	LatexUtilityForPredefinedDatasetsResultsClass.predefinedDatasetFoldsResultsTableCreatorClass.printLatexPredefinedDatasetFoldsResultsTableHeaderFirstPartToTheFile(outForPredefinedDatasetsFoldsResultsFile, datasetName);
    	predefinedDatasetExtendedResultsTableCreatorClass.printLatexPredefinedDatasetExtendedResultsTableHeaderFirstPartToTheFile(outForPredefinedDatasetsExtendedResultsFile, datasetName);
    }    
    
    static void evaluationOfOnePredefinedDatasetIsCompletedEvent(ArrayList<ResultClassListClass> resultsOfAlgorihms, GraphClass graph, String datasetName)
    {        
    	
    	CorrelationManagerClass correlationManager = CorrelationManagerClass.createCorrelationsResults(graph, datasetName);
    	
		LatexUtilityForPredefinedDatasetsResultsClass.predefinedDatasetSummaryResultsTableCreatorClass.addRecordToThePredefinedDatasetSummaryResultsTable(outForPredefinedDatasetsSummaryResultsFile, resultsOfAlgorihms);
		LatexUtilityForPredefinedDatasetsResultsClass.predefinedDatasetFoldsResultsTableCreatorClass.addRecordToThePredefinedDatasetFoldsResultsTable(outForPredefinedDatasetsFoldsResultsFile, resultsOfAlgorihms);
		predefinedDatasetExtendedResultsTableCreatorClass.addRecordToThePredefinedDatasetExtendedResultsTable(outForPredefinedDatasetsExtendedResultsFile, resultsOfAlgorihms, graph, correlationManager.correlations);
		LatexUtilityForPredefinedDatasetsResultsClass.increasePredefinedDatasetIndex();
		
    	if(resultsForCO!=null)
    		resultsForCO.clear();
    	if(resultsForLO!=null)
    		resultsForLO.clear();
    	if(resultsForICA!=null)
    		resultsForICA.clear();
    	
    	if(resultsForAVE!=null)
    		resultsForAVE.clear();
    	if(resultsForMAX!=null)
    		resultsForMAX.clear();
    	if(resultsForPROD!=null)
    		resultsForPROD.clear();
    	if(resultsForLA!=null)
    		resultsForLA.clear();    	
    	if(resultsForDFMM!=null)
    		resultsForDFMM.clear();
    	if(resultsForLB!=null)
    		resultsForLB.clear(); 
    	if(resultsForLAMAX!=null)
    		resultsForLAMAX.clear();
    	if(resultsForLBMAX!=null)
    		resultsForLBMAX.clear();
    }
    
    static void predefinedDataTestEndEvent(String datasetName)
    {    	         
    //	LatexUtilityForPredefinedDatasetsResultsClass.predefinedDatasetSummaryResultsTableCreatorClass.printLatexPredefinedResultsTableHeaderEndPartToTheFile(outForPredefinedDatasetsSummaryResultsFile, datasetName);
    //	LatexUtilityForPredefinedDatasetsResultsClass.predefinedDatasetFoldsResultsTableCreatorClass.printLatexPredefinedDatasetFoldsResultsTableHeaderEndPartToTheFile(outForPredefinedDatasetsFoldsResultsFile, datasetName);	
    //	predefinedDatasetExtendedResultsTableCreatorClass.printLatexPredefinedDatasetExtendedResultsTableHeaderEndPartToTheFile(outForPredefinedDatasetsExtendedResultsFile, datasetName);
    }
 }
